//
//  WYRegionView.m
//  Boss
//
//  Created by admin on 2018/6/6.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYRegionView.h"
#import "UIImage+DrawWithColor.h"
@interface WYRegionView()

@property (nonatomic,strong)NSMutableArray *btnArray;

@end
@implementation WYRegionView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.btnArray = [NSMutableArray array];
        [self createSubViews];
    }
    
    return self;
}
-(void)createSubViews
{
    UILabel *sendLabel = [[UILabel alloc]init];
    [self addSubview:sendLabel];
    sendLabel.text = @"发布范围";
    sendLabel.font = kFontSystemBIgger2(14);
    sendLabel.textColor = [UIColor hexStringToColor:@"#aaaaaa" alpha:1.0];
    
    [sendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(20);
    }];
    
    UIButton *threeBtn =[[UIButton alloc]init];
    UIButton *regionBtn =[[UIButton alloc]init];
    UIButton *cityBtn =[[UIButton alloc]init];
    UIButton *countryBtn = [[UIButton alloc]init];
    
    [self addSubview:countryBtn];
    [self addSubview:threeBtn];
    [self addSubview:regionBtn];
    [self addSubview:cityBtn];
    
    [threeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(sendLabel.mas_right).offset(10);
        make.top.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
        make.right.equalTo(regionBtn.mas_left).offset(-10);
        make.width.equalTo(@[regionBtn,cityBtn,countryBtn]);
    }];
    
    [regionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(threeBtn.mas_right).offset(10);
        make.top.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
        make.right.equalTo(cityBtn.mas_left).offset(-10);
        make.width.equalTo(@[threeBtn,cityBtn,countryBtn]);
    }];
    
    [cityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(regionBtn.mas_right).offset(10);
        make.top.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
        make.right.equalTo(countryBtn.mas_left).offset(-10);
        make.width.equalTo(@[regionBtn,threeBtn,countryBtn]);
    }];
    
    [countryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cityBtn.mas_right).offset(10);
        make.top.mas_equalTo(16);
        make.bottom.mas_equalTo(-16);
        make.right.mas_equalTo(-16);
        make.width.equalTo(@[regionBtn,threeBtn,cityBtn]);
    }];
    
    
    
    
    
    [threeBtn setTitle:@"三公里" forState:UIControlStateNormal];
    [threeBtn setTitleColor:[UIColor hexStringToColor:@"#333333" alpha:1.0] forState:UIControlStateNormal];
    [threeBtn setTitleColor:[UIColor hexStringToColor:@"#ffffff" alpha:1.0] forState:UIControlStateSelected];
    [threeBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#f7f7f7" alpha:1.0]] forState:UIControlStateNormal];
    [threeBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#d8593f" alpha:1.0]] forState:UIControlStateSelected];
    
    [regionBtn setTitle:@"全区/县" forState:UIControlStateNormal];
    [regionBtn setTitleColor:[UIColor hexStringToColor:@"#333333" alpha:1.0] forState:UIControlStateNormal];
    [regionBtn setTitleColor:[UIColor hexStringToColor:@"#ffffff" alpha:1.0] forState:UIControlStateSelected];
    [regionBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#f7f7f7" alpha:1.0]] forState:UIControlStateNormal];
    [regionBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#d8593f" alpha:1.0]] forState:UIControlStateSelected];
    
    [cityBtn setTitle:@"全市" forState:UIControlStateNormal];
    [cityBtn setTitleColor:[UIColor hexStringToColor:@"#333333" alpha:1.0] forState:UIControlStateNormal];
    [cityBtn setTitleColor:[UIColor hexStringToColor:@"#ffffff" alpha:1.0] forState:UIControlStateSelected];
    [cityBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#f7f7f7" alpha:1.0]] forState:UIControlStateNormal];
    [cityBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#d8593f" alpha:1.0]] forState:UIControlStateSelected];
    
    [countryBtn setTitle:@"全国" forState:UIControlStateNormal];
    
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    if (userMessage.vipId.integerValue==30) {
        [countryBtn setTitleColor:[UIColor hexStringToColor:@"#333333" alpha:1.0] forState:UIControlStateNormal];
    }else{
        [countryBtn setTitleColor:[UIColor hexStringToColor:@"#999999" alpha:1.0] forState:UIControlStateNormal];
    }
    
    
    [countryBtn setTitleColor:[UIColor hexStringToColor:@"#ffffff" alpha:1.0] forState:UIControlStateSelected];
    [countryBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#f7f7f7" alpha:1.0]] forState:UIControlStateNormal];
    [countryBtn setBackgroundImage:[UIImage imageWithColor:[UIColor hexStringToColor:@"#d8593f" alpha:1.0]] forState:UIControlStateSelected];
    
    
    
     [threeBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
     [regionBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
     [cityBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
     [countryBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
     threeBtn.tag = 1;
     regionBtn.tag = 2;
     cityBtn.tag = 3;
    countryBtn.tag = 5;
    [threeBtn setCornerRadius:2.f];
    [regionBtn setCornerRadius:2.f];
    [cityBtn setCornerRadius:2.f];
    [countryBtn setCornerRadius:2.f];
    [threeBtn setBorderWithWidth:kLineHeight andColor:[UIColor hexStringToColor:@"#eaeaea" alpha:1.0]];
    [regionBtn setBorderWithWidth:kLineHeight andColor:[UIColor hexStringToColor:@"#eaeaea" alpha:1.0]];
    [cityBtn setBorderWithWidth:kLineHeight andColor:[UIColor hexStringToColor:@"#eaeaea" alpha:1.0]];
    [countryBtn setBorderWithWidth:kLineHeight andColor:[UIColor hexStringToColor:@"#eaeaea" alpha:1.0]];
    threeBtn.titleLabel.font = kFontSystemBIgger2(14);
    regionBtn.titleLabel.font = kFontSystemBIgger2(14);
    cityBtn.titleLabel.font = kFontSystemBIgger2(14);
    countryBtn.titleLabel.font = kFontSystemBIgger2(14);
    [self.btnArray addObject:threeBtn];
    [self.btnArray addObject:regionBtn];
    [self.btnArray addObject:cityBtn];
     [self.btnArray addObject:countryBtn];
}

-(void)clickButton:(UIButton *)btn
{
    
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    
    if (userMessage.vipId.integerValue!=30&&btn.tag==5) {
        if (self.complete) {
            self.complete(@"", 0);
        }
    }else{
        
        if (self.complete) {
            self.complete(btn.titleLabel.text, btn.tag);
        }
        for (UIButton *btn in self.btnArray) {
            btn.selected = NO;
        }
        btn.selected = !btn.isSelected;
        NSLog(@"%ld",btn.tag);
        
    }
   
    
}





@end
